<template>
  <div class="contact-info">
    <div class="contact-name">{{ contact.name }}</div>
    <div class="contact-status" :class="`status--${contact.status}`">
      {{ getStatusText(contact.status) }}
    </div>
    <div v-if="contact.lastMessage" class="contact-last-message">
      {{ contact.lastMessage }}
    </div>
  </div>
</template>

<script setup lang="ts">
import type { Contact, ContactStatus } from './types/index.ts'

interface Props {
  contact: Contact
}

defineProps<Props>()

const getStatusText = (status: ContactStatus): string => {
  const statusMap: Record<ContactStatus, string> = {
    online: '在线',
    away: '离开',
    busy: '忙碌',
    offline: '离线'
  }
  return statusMap[status] || '未知'
}
</script>

<style scoped>
.contact-info {
  flex: 1;
  min-width: 0;
}

.contact-name {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-color-primary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-status {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status--online {
  background-color: #e8f5e8;
  color: #2e7d32;
}

.status--away {
  background-color: #fff3e0;
  color: #ef6c00;
}

.status--busy {
  background-color: #ffebee;
  color: #c62828;
}

.status--offline {
  background-color: var(--background-color-tertiary);
  color: var(--text-color-secondary);
}

.contact-last-message {
  font-size: 14px;
  color: var(--text-color-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 4px;
}
</style>
